/**
 * Copyright (C), 2021-2023, 四信物联网有限公司
 * FileName: Message
 * Author:   Chapin
 * Date:     2023/10/23 11:29
 * Description: 消息抽象类
 * History:
 * <author>          <time>          <version>          <desc>
 * 作者姓名           修改时间           版本号              描述
 */
package com.fourfaith.iot.beidou.message;

import com.fourfaith.iot.beidou.message.inbound.*;
import com.fourfaith.iot.beidou.message.outbound.CCicrMessage;
import com.fourfaith.iot.beidou.message.outbound.CCtcqMessage;
import lombok.Data;

import java.io.Serializable;
import java.util.HashMap;
import java.util.Map;

/**
 * 〈消息抽象类〉
 * @author Chapin
 * @create 2023/10/23
 * @since 1.0.0
 */
@Data
public abstract class Message implements Serializable {

    /**
     * 命令码
     */
    private String command;

    /**
     * 北斗指令码及消息对象
     */
    public static final String BDTCI = "BDTCI";
    public static final String BDFKI = "BDFKI";
    public static final String BDICP = "BDICP";
    public static final String BDIBD = "BDIBD";
    public static final String BDPWI = "BDPWI";
    public static final String CCTCQ = "CCTCQ";
    public static final String CCICR = "CCICR";

    /**
     * 获取命令码
     * @return
     */
    public abstract String getCommand();

    /**
     * 存放功能码和消息对象
     */
    private static Map<String, Class<?>> messageClassMap = new HashMap<>();

    public static final Class<?> getMessageClass(String command){
        return messageClassMap.get(command);
    }


    static {
        messageClassMap.put(BDTCI, BDtciMessage.class);
        messageClassMap.put(BDFKI, BDfkiMessage.class);
        messageClassMap.put(BDICP, BDicpMessage.class);
        messageClassMap.put(BDIBD, BDibdMessage.class);
        messageClassMap.put(BDPWI, BDpwiMessage.class);
        messageClassMap.put(CCTCQ, CCtcqMessage.class);
        messageClassMap.put(CCICR, CCicrMessage.class);
    }
}